/*=========================================================================
 * Copyright (c) 2010-2011 VMware, Inc. All rights reserved.
 * This product is protected by U.S. and international copyright
 * and intellectual property laws. VMware products are covered by
 * one or more patents listed at http://www.vmware.com/go/patents.
 *=========================================================================
 */
package com.gemfire.onlineretailer.client;

import java.io.IOException;

import com.gemstone.gemfire.cache.query.CqClosedException;
import com.gemstone.gemfire.cache.query.CqException;
import com.gemstone.gemfire.cache.query.CqExistsException;
import com.gemstone.gemfire.cache.query.FunctionDomainException;
import com.gemstone.gemfire.cache.query.NameResolutionException;
import com.gemstone.gemfire.cache.query.QueryInvalidException;
import com.gemstone.gemfire.cache.query.QueryInvocationTargetException;
import com.gemstone.gemfire.cache.query.TypeMismatchException;
import com.springsource.gemfire.training.accounts.payable.dao.AccountPayableGemfireDAO;
import com.springsource.gemfire.training.accounts.payable.ui.AccountsPayableCommandLineUI;

/**
 * This class is created from a similar example tutorial in the Gemfire
 * distribution. launches a command line user interface for the PaymentVoucher
 * processing application.
 * 
 * @author GemStone Systems, Inc.
 * @author Binit Datta
 */
public class Client {

	public static void main(String[] args)  {
		try {
			OnlineRetailerDAO dao = new OnlineRetailerDAO();
			dao.initClient();
			AccountsPayableCommandLineUI ui = new AccountsPayableCommandLineUI(
					dao, System.in, System.out);

			ui.processPayments();

			ui.queryItems();

			ui.queryRawMaterialsItem();

			ui.queryAccountHeads();

			/*
			 * This will show how payment vouchers created from different
			 * Clients are seen as a logical single Region even if they are
			 * cached by different servers.
			 */

			ui.queryPaymentVouchers();
			
			ui.executeItemFunction();
			
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (FunctionDomainException fde) {
			fde.printStackTrace();

		} catch (TypeMismatchException tme) {
			tme.printStackTrace();

		} catch (NameResolutionException nre) {
			nre.printStackTrace();

		} catch (QueryInvocationTargetException qite) {
			qite.printStackTrace();

		} catch (CqClosedException cqce) {
			cqce.printStackTrace();

		} catch (QueryInvalidException qie) {
			qie.printStackTrace();
			
		} catch (CqExistsException cee) {
			cee.printStackTrace();

		} catch (CqException ce) {
			ce.printStackTrace();
		}
	}

}
